<template>
  <div class="Sex">
    <ScreenTitle v-model:title-value="titleValue"></ScreenTitle>
    <div class="center">
      <div class="man"><img src="../../images/man.png" alt="" /></div>
      <div class="women"><img src="../../images/woman.png" alt="" /></div>
    </div>
    <div class="rate">
      <p>男士58%</p>
      <p>女士42%</p>
    </div>
    <div class="charts" ref="charts"></div>
  </div>
</template>

<script lang="ts" setup name="Sex">
import { onMounted, ref, inject } from 'vue'

let titleValue = ref('男女比例')
const charts = ref()

const initEchartsOneFn = () => {
  // echarts初始化
  const Echarts = inject('$echarts')

  let myChart = (Echarts as any).init(charts.value)
  // 或
  // let myChart = proxy.$echarts.init(container.value);
  const option = {
    //标题组件
    title: {
      text: '男女比例',
      left: '42%',
      textStyle: {
        color: 'skyblue'
      }
    },
    //x|y轴组件
    xAxis: {
      show: false,
      min: 0,
      max: 100
    },
    yAxis: {
      show: false,
      type: 'category'
    },
    //系列:决定你展示什么样的图形图标
    series: [
      {
        type: 'bar',
        data: [58],
        barWidth: '25',
        z: 100,
        itemStyle: {
          color: 'skyblue',
          borderRadius: 30
        }
      },
      {
        type: 'bar',
        data: [100],
        barWidth: '25',
        barGap: '-100%',
        itemStyle: {
          color: 'pink',
          borderRadius: 30
        }
      }
    ],
    //布局组件
    grid: {
      left: 0,
      right: 0,
      top: 0,
      bottom: 0
    }
  }

  myChart.setOption(option)
}
onMounted(() => {
  initEchartsOneFn()
})
</script>

<style scoped>
.Sex {
  
  width: 100%;
  height: 100%;
  background: url(../../images/dataScreen-main-cb.png) no-repeat;
  background-size: 100% 100%;
  margin: 20px 0px;

  .center {
    display: flex;
    justify-content: center;
    .man {
      margin: 20px;

      width: 110px;
      height: 115px;
      background: url(../../images/man-bg.png) no-repeat;
      background-size: 100%, 100%;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .women {
      margin: 20px;
      width: 110px;
      height: 115px;
      background: url(../../images/woman-bg.png) no-repeat;
      background-size: 100%, 100%;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
  .rate {
    display: flex;
    justify-content: space-between;
    margin-left: 20px;
    margin-right: 20px;
  }
  .charts {
    height: 100px;
    width: 100%;
    padding-left: 10px;
    padding-right: 10px;
  }
}
</style>
